import moment from 'moment/moment';

const tableOption = {
  border: true,
  addBtn: false,
  viewBtn: false,
  editBtn: false,
  delBtn: false,
  index: true,
  menu: false,
  columnBtn: false,
  refreshBtn: false,
  indexLabel: '序号',
  column: [
    {
      label: '日期',
      prop: 'windowTime'
    },
    {
      label: '产线',
      prop: 'lineName'
    },
    {
      label: '产品名称',
      prop: 'currPartName'
    },
    {
      label: '产品编码',
      prop: 'currPartNo'
    },
    {
      label: '工单号',
      prop: 'currWorkOrderNo',
      span: 7
    },
    {
      label: '上个产品名称',
      prop: 'prePartName'
    },
    {
      label: '上个产品编码',
      prop: 'prePartNo'
    },
    {
      label: '上个产品工单号',
      prop: 'preWorkOrderNo'
    },
    {
      label: '换线开始时间',
      prop: 'changeFrom'
    },
    {
      label: '换线完成时间',
      prop: 'changeEnd'
    },
    {
      label: '换线总时间',
      prop: 'durationFormatter'
    }
  ]
};

const option = {
  menuPosition: 'right',
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '时间范围',
      span: 6,
      prop: 'examineDate',
      type: 'daterange',
      format: 'yyyy-MM-dd',
      valueFormat: 'yyyy-MM-dd',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() || moment(time).format('yyyy-MM-DD') === moment(new Date()).format('yyyy-MM-DD');
        }
      },
      rules: [
        {
          required: true,
          message: '请选择时间范围',
          trigger: 'blur'
        },
        {
          trigger: 'change',
          validator: (rule, value, callback) => {
            const endTime = value[1];
            const startTime = value[0];
            if (moment(endTime).diff(moment(startTime), 'day') > 31) {
              callback(new Error('查询时间最多选择一个月时间'));
            }
            callback();
          }
        }
      ]
    },
    {
      label: '产线名称',
      prop: 'lineId',
      span: 6,
      type: 'select',
      dicData: [],
      rules: [
        {
          required: true,
          message: '请选择产线名称',
          trigger: 'blur'
        }
      ]
    },
    {
      label: '',
      prop: 'btn',
      span: 10,
      formslot: true
    }
  ]
};

export { tableOption, option };
